﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Intersection
{
    class FileManager
    {
        static public ObsData ReadImageParam(string path)
        {
            ImageParam left = new ImageParam();
            ImageParam right = new ImageParam();
            ObsData data = new ObsData();
            data.Img_left = left;
            data.Img_right = right;
            using (var reader = new StreamReader(path))
            {
                left.Xs = Convert.ToDouble(reader.ReadLine());
                left.Ys = Convert.ToDouble(reader.ReadLine());
                left.Zs = Convert.ToDouble(reader.ReadLine());
                left.phi = Convert.ToDouble(reader.ReadLine());
                left.omega = Convert.ToDouble(reader.ReadLine());
                left.kappa = Convert.ToDouble(reader.ReadLine());
                left.x = Convert.ToDouble(reader.ReadLine());
                left.y = Convert.ToDouble(reader.ReadLine());
                left.f = Convert.ToDouble(reader.ReadLine());

                right.Xs = Convert.ToDouble(reader.ReadLine());
                right.Ys = Convert.ToDouble(reader.ReadLine());
                right.Zs = Convert.ToDouble(reader.ReadLine());
                right.phi = Convert.ToDouble(reader.ReadLine());
                right.omega = Convert.ToDouble(reader.ReadLine());
                right.kappa = Convert.ToDouble(reader.ReadLine());
                right.x = Convert.ToDouble(reader.ReadLine());
                right.y = Convert.ToDouble(reader.ReadLine());
                right.f = Convert.ToDouble(reader.ReadLine());
            }
            return data;
        }

        static public void ReadCorrPoints(ref ObsData obsdata, string path)
        {
            List<CorrPoints> data = new List<CorrPoints>();
            using (var reader = new StreamReader(path))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    string[] parts = line.Split(',');
                    CorrPoints pts = new CorrPoints();
                    pts.x1 = int.Parse(parts[0]);
                    pts.y1 = int.Parse(parts[1]);
                    pts.f1 = obsdata.Img_left.f;
                    pts.x2 = int.Parse(parts[2]);
                    pts.y2 = int.Parse(parts[3]);
                    pts.f2 = obsdata.Img_right.f;
                    data.Add(pts);
                }
            }
            obsdata.Data = data;
        }
    }
}
